@inject('request', 'Illuminate\Http\Request')
@extends('layouts.app')

@section('content')
<h3 class="page-title">@lang('global.manage.roles.title')</h3>
@if(Gate::allows('create roles'))
<p>
    <a href="{{ route('admin.manage.roles.create') }}" class="btn btn-success">@lang('global.app_add_new')</a>
</p>
@endif
<div class="panel panel-default">
    <div class="panel-heading">
        @lang('global.app_list')
    </div>

    <div class="panel-body table-responsive">
        <table class="table table-bordered table-striped {{ count($roles) > 0 ? 'datatable' : '' }} dt-select">
            <thead>
                <tr>
                    <th style="text-align:center;"><input type="checkbox" id="select-all" /></th>
                    <th>@_lang('fields.name')</th>
                    <th>@_lang('fields.check_permission')</th>
                    <th>@lang('global.app_operate')</th>
                </tr>
            </thead>

            <tbody>
                @if (count($roles) > 0)
                @foreach ($roles as $role)
                <tr data-entry-id="{{ $role->id }}">
                    <td></td>
                    <td>{{ $role->name }}</td>
                    <td style="line-height:25px;">
                        @foreach ($role->permissions()->pluck('name') as $permission)
                            @if(!empty(count($Permissions)))
                                @foreach($Permissions as $per_k => $per)
                                    @if($permission ==$per['name'])
                                        @if(!empty($per->hasDetails))
                                            <span class="label label-info label-many">{{$per->hasDetails['explain']}}</span>
                                        @else
                                            <span class="label label-info label-many"> {{$per['name']}}</span>
                                        @endif
                                    @else
                                        <!-- <span class="label label-info label-many">{{ $permission }}</span> -->
                                    @endif
                                @endforeach
                            @else
                                <span class="label label-info label-many">{{ $permission }}</span>
                            @endif
                        @endforeach
                    </td>
                    <td>
                        @if(Gate::allows('update roles'))
                        <a href="{{ route('admin.manage.roles.edit',[$role->id]) }}" class="btn btn-xs btn-info">@lang('global.app_edit')</a>
                        @endif
                        @if(Gate::allows('delete roles'))
                        {!! Form::open(array(
                        'style' => 'display: inline-block;',
                        'method' => 'DELETE',
                        'onsubmit' => "return confirm('".trans("global.app_are_you_sure")."');",
                        'route' => ['admin.manage.roles.destroy', $role->id])) !!}
                        {!! Form::submit(trans('global.app_delete'), array('class' => 'btn btn-xs btn-danger')) !!}
                        {!! Form::close() !!}
                        @endif
                    </td>
                </tr>
                @endforeach
                @else
                <tr>
                    <td colspan="6">@lang('global.app_no_entries_in_table')</td>
                </tr>
                @endif
            </tbody>
        </table>
    </div>
</div>
@stop

@section('javascript')
<script>
    window.route_mass_crud_entries_destroy = '{{ url('
    admin.manage.roles.mass_destroy ') }}';
</script>
@endsection